<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "{{%code}}".
 *
 * @property int $id
 * @property string $goods_sn 产品识别码
 * @property string $security_sn 防伪码
 * @property string $bar_code 条形码
 * @property string $identity_code 身份码
 * @property int $status 使用状态
 * @property string $link 二维码连接
 * @property int $created_at 创建时间
 * @property int $updated_at 修改时间
 * @property int $is_receive 是否领取
 * @property string $price 价格
 * @property Product $product
 */
class Code extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%code}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['goods_sn', 'security_sn', 'bar_code', 'identity_code', 'status', 'created_at', 'updated_at'], 'required'],
            [['status', 'created_at', 'updated_at'], 'integer'],
//            [['goods_sn'], 'string', 'max' => 11],
            [['link', 'price'], 'string', 'max' => 1000],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => ' 序号',
            'goods_sn' => '产品识别码',
            'security_sn' => '防伪码',
            'bar_code' => '一维码',
            'identity_code' => ' 身份码',
            'status' => ' 使用状态',
            'link' => 'Link',
            'created_at' => '创建时间',
            'updated_at' => '修改时间',
            'is_receive' => '是否领取',
            'price' => '价格',
        ];
    }

    public function getProduct()
    {
        return $this->hasOne(Product::className(), ['goods_sn' => 'goods_sn']);
    }

}
